package com.enterprise.controller.manage;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.enterprise.cache.FrontCache;
import com.enterprise.controller.BaseController;
import com.enterprise.entity.CaseType;
import com.enterprise.entity.PageConfig;
import com.enterprise.entity.page.PageModel;
import com.enterprise.service.PageConfigService;
import com.enterprise.service.Services;

@Controller
@RequestMapping("/manage/pageConfig/")
public class PageConfigAction extends BaseController<PageConfig>{
	
	private static final String page_toList = "/manage/pageConfig/pageConfigList";
	private static final String page_toEdit = "/manage/pageConfig/pageConfigEdit";
	private static final String page_toAdd = "/manage/pageConfig/pageConfigEdit";
	
	public  PageConfigAction() {
		super.page_toList = page_toList;
		super.page_toEdit = page_toEdit;
		super.page_toAdd = page_toAdd;
	}
	
	@Autowired
    private FrontCache frontCache;
	
	@Autowired
	PageConfigService pageConfigService;

	@Override
	public Services<PageConfig> getService() {
		// TODO Auto-generated method stub
		return pageConfigService;
	}
	
	@Override
	public String selectList(HttpServletRequest request, PageConfig pageConfig){	
		List<PageConfig> pageConfigList = pageConfigService.selectList(pageConfig);
		request.setAttribute("pageConfigList", pageConfigList);
		return page_toList;
		
	}
	
	@Override
	public String insert(HttpServletRequest request , @ModelAttribute("e") PageConfig e,RedirectAttributes flushAttrs) throws Exception{
		getService().insert(e);
		insertAfter(e);
		addMessage(flushAttrs,"操作成功！");
		frontCache.loadPageConfig();//加载缓存
		return "redirect:selectList";
	}
	
	 public String update(HttpServletRequest request, @ModelAttribute("e") PageConfig e, RedirectAttributes flushAttrs) throws Exception {
	        getService().update(e);
	        insertAfter(e);
	        addMessage(flushAttrs, "操作成功！");
	        frontCache.loadPageConfig();//加载缓存
	        return "redirect:selectList";
	    }
	
	 public String toDel(@ModelAttribute("e") PageConfig e ,RedirectAttributes flushAttrs) throws Exception{
			getService().delete(e);
			addMessage(flushAttrs,"操作成功！");
			frontCache.loadPageConfig();//加载缓存
			return "redirect:selectList";
		}

}
